package com.soup.lab.config;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.SmartLifecycle;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;

import java.util.List;

@Configuration
public class LifeCycleConfiguration {

    @Bean
    public A a() {
        return new A();
    }

    @Bean
    @Qualifier("child")
    public B b() {
        return new B();
    }

    @Bean
    @Qualifier("child")
    public C c() {
        return new C();
    }

    @Bean
    public D d(@Qualifier("child") List<A> as) {
        return new D(as);
    }

    static class B extends A{}

    static class C extends A{}

    public static class D {
        private List<A> list;

        public D(List<A> list) {
            this.list = list;
        }

        public List<A> getList() {
            return list;
        }
    }

    static class A implements SmartLifecycle {

        boolean running;

        @Override
        public void start() {
            System.out.println("A is started");
            running = true;
        }

        @Override
        public void stop() {
            System.out.println("A is stopped");
            running = false;
        }

        @Override
        public boolean isRunning() {
            return running;
        }
    }

}
